/**
 * 增强对象字面量
 * 解决的问题：缩减代码
 * 
 * 
 * 
 */
function createBookShop(inventory){
    return{
        inventory,          //inventory:inventory
        inventoryValue(){   //inventoryValue:function(){}
            return this.inventory.reduce((total,book)=>total+book.price,0);
        },
        priceForTitle(title){   //同理
            return this.inventory.find(book=>book.title===title).price;
        }
    }
}

const inventory=[
    {title:"Vue",price:10},
    {title:"Angular",price:15}
];

const bookShop=createBookShop(inventory);
console.log(bookShop.inventoryValue());
console.log(bookShop.priceForTitle("Angular"));